<div class="panel panel-default panel-intro">
    {:build_heading()}

    <style>
        .spec-btn{
            margin-right: 10px;
        }
    </style>

    <div class="panel-body">
        <form id="add-form" class="form-horizontal add-form" role="form" data-toggle="validator" method="POST" action="">
            
            
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#info" aria-controls="info" role="tab" data-toggle="tab">商品信息</a></li>
                <li role="presentation"><a href="#imgs" aria-controls="imgs" role="tab" data-toggle="tab">商品附图</a></li>
                <li role="presentation"><a href="#spec" aria-controls="spec" role="tab" data-toggle="tab">商品规格</a></li>
                <li role="presentation"><a href="#attribute" aria-controls="attribute" role="tab" data-toggle="tab">商品属性</a></li>
            </ul>

            <!-- Tab panes -->
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="info">
                    <div class="form-group"></div>

                    <div class="form-group">
                        <label for="c-category_id" class="control-label col-xs-12 col-sm-2">{:__('Category_id')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select name="row[category_id]" data-rule="required" id="c-category_id" class="form-control" v-model="category_id">
                                <option value="">分类</option>
                                {foreach name="categorys" item="vo"}
                                    <option value="{$vo.id}" >{$vo.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-brand_id" class="control-label col-xs-12 col-sm-2">{:__('Brand_id')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-brand_id"  data-source="brand/index" class="form-control selectpage" name="row[brand_id]" type="text" value="{$row['brand_id']?:''}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-goods_name" class="control-label col-xs-12 col-sm-2">{:__('Goods_name')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-goods_name" data-rule="required" class="form-control" name="row[goods_name]" type="text" value="{$row['goods_name']?:''}" >
                        </div>
                    </div>

                    <input type="hidden" name="row[goods_type]" value="1">
                    

                    <div class="form-group" v-if="goods_type == 2">
                        <label for="c-send_number" class="control-label col-xs-12 col-sm-2">发货次数: </label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-send_number" data-rule="required" class="form-control" name="row[send_number]" type="number" value="{$row['send_number']?:'0'}">
                        </div>
                    </div>

                    <div class="form-group" v-if="goods_type == 2">
                        <label for="c-send_day" class="control-label col-xs-12 col-sm-2">发货间隔(天): </label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-send_day" data-rule="required" class="form-control" name="row[send_day]" type="number" value="{$row['send_day']?:'0'}">
                        </div>
                    </div>

                    <div class="form-group hidden" v-if="goods_type == 3">
                        <label for="c-use_day" class="control-label col-xs-12 col-sm-2">使用时间(天): </label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-use_day"  class="form-control" name="row[use_day]" type="number" value="{$row['use_day']?:'0'}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-open_user_grade" class="control-label col-xs-12 col-sm-2">{:__('Open_user_grade')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <div class="radio">
                                {foreach name="levelList" item="vo"}
                                    <label for="c-open_user_grade-{$key}">
                                        <input type="radio"id="c-open_user_grade-{$key}" name="row[open_user_grade]" value="{$key}"  v-model="row.open_user_grade"> {$vo}
                                    </label> 
                                {/foreach}

                            </div>
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="c-click_count" class="control-label col-xs-12 col-sm-2">{:__('Click_count')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-click_count" class="form-control" name="row[click_count]" type="number" value="{$row['click_count']?:'0'}">
                        </div>
                    </div>
                   
                    <div class="form-group">
                        <label for="c-store_count" class="control-label col-xs-12 col-sm-2">{:__('Store_count')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-store_count" class="form-control" name="row[store_count]" type="number"  value="{$row['store_count']?:'0'}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-weight" class="control-label col-xs-12 col-sm-2">{:__('Weight')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-weight"  class="form-control" name="row[weight]" type="number"  value="{$row['weight']?:'0'}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-market_price" class="control-label col-xs-12 col-sm-2">{:__('Market_price')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-market_price" data-rule="required" class="form-control" step="0.01" name="row[market_price]" type="number"  value="{$row['market_price']?:'0'}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-shop_price" class="control-label col-xs-12 col-sm-2">{:__('Shop_price')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-shop_price" data-rule="required" class="form-control" step="0.01" name="row[shop_price]" type="number" value="{$row['shop_price']?:'0'}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-use_point" class="control-label col-xs-12 col-sm-2">{:__('Use_point')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-use_point" data-rule="required" class="form-control" step="0.01" name="row[use_point]" type="number" value="{$row['use_point']?:'0'}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-cost_price" class="control-label col-xs-12 col-sm-2">{:__('Cost_price')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-cost_price" class="form-control" step="0.01" name="row[cost_price]" type="number" value="{$row['cost_price']?:'0'}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-keywords" class="control-label col-xs-12 col-sm-2">{:__('Keywords')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-keywords"  class="form-control" name="row[keywords]" type="text" value="{$row['keywords']?:''}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-goods_remark" class="control-label col-xs-12 col-sm-2">{:__('Goods_remark')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-goods_remark" class="form-control" name="row[goods_remark]" type="text"  value="{$row['goods_remark']?:''}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-content" class="control-label col-xs-12 col-sm-2">{:__('Content')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <textarea id="c-content" class="form-control editor" rows="5" name="row[content]" cols="50">{$row['content']?:''}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-original_image" class="control-label col-xs-12 col-sm-2">主图:</label>
                        <div class="col-xs-12 col-sm-8">
                            <div class="input-group">
                                <input id="c-original_image" class="form-control" size="50" name="row[original_image]" type="text" value="{$row['original_image']?:''}">
                                <div class="input-group-addon no-border no-padding">
                                    <span><button type="button" id="plupload-original_image" class="btn btn-danger plupload" data-input-id="c-original_image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-original_image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                                    <span><button type="button" id="fachoose-original_image" class="btn btn-primary fachoose" data-input-id="c-original_image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                                </div>
                                <span class="msg-box n-right" for="c-original_image"></span>
                            </div>
                            <ul class="row list-inline plupload-preview" id="p-original_image"></ul>
                        </div>
                    </div>

          
                    <div class="form-group">
                        <label for="c-is_on_sale" class="control-label col-xs-12 col-sm-2">{:__('Is_on_sale')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            {:build_radios('row[is_on_sale]', $isOnSaleList, isset($row['is_on_sale'])?$row['is_on_sale']:1)}
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-is_on_sale" class="control-label col-xs-12 col-sm-2">{:__('其它')}:</label>
                        <div class="col-xs-12 col-sm-8">
                                <label for="c-is_recommend" class="checkbox-inline">
                                    <input type="checkbox" name="row[is_recommend]" id="c-is_recommend" v-model="row.is_recommend" value="1"> {:__('Is_recommend')}
                                </label>

                                <label for="c-is_new" class="checkbox-inline">
                                    <input type="checkbox" name="row[is_new]" id="c-is_new" v-model="row.is_new" value="1"> {:__('Is_new')}
                                </label>

                                <label for="c-is_hot" class="checkbox-inline">
                                    <input type="checkbox" name="row[is_hot]" id="c-is_hot" v-model="row.is_hot" value="1"> {:__('Is_hot')}
                                </label>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-effective_time" class="control-label col-xs-12 col-sm-2">{:__('Effective_time')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-effective_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[effective_time]" type="text" value="{:date('Y-m-d H:i:s')}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-is_free_shipping" class="control-label col-xs-12 col-sm-2">{:__('Is_free_shipping')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <div class="radio">
                                {foreach name="isFreeShippingList" item="vo"}
                                    <label for="c-is_free_shipping_{$key}">
                                        <input type="radio" name="row[is_free_shipping]" id="c-is_free_shipping_{$key}" value="{$key}"   v-model="row.is_free_shipping"> {$vo}
                                    </label>
                                {/foreach}
                            </div> 
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-shipping_template_id" class="control-label col-xs-12 col-sm-2">运费模板:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select name="row[shipping_template_id]" v-model="row.shipping_template_id" class="form-control" id="c-shipping_template_id">
                                {foreach name="shippingTemplates" id="st"}
                                    <option value="{$st.id}">{$st.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-sort" class="control-label col-xs-12 col-sm-2">{:__('Sort')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-sort" data-rule="required" class="form-control" name="row[sort]" type="number" value="{$row['sort']?:'50'}">
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="c-give_integral" class="control-label col-xs-12 col-sm-2">{:__('Give_integral')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-give_integral" class="form-control" name="row[give_integral]" type="number" value="{$row['give_integral']?:'0'}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-give_balance" class="control-label col-xs-12 col-sm-2">{:__('Give_balance')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-give_balance" class="form-control" name="row[give_balance]" type="number" value="{$row['give_balance']?:'0'}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="c-add_days" class="control-label col-xs-12 col-sm-2">{:__('Add_days')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-add_days" class="form-control" name="row[add_days]" type="number" value="{$row['add_days']?:'0'}">
                        </div>
                    </div>

                   <!--  <div class="form-group">
                        <label for="c-exchange_integral" class="control-label col-xs-12 col-sm-2">{:__('Exchange_integral')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-exchange_integral" data-rule="required" class="form-control" name="row[exchange_integral]" type="number" value="{$row['exchange_integral']?:'0'}">
                        </div>
                    </div> -->

           

                    <div class="form-group">
                        <label for="c-rebate_type" class="control-label col-xs-12 col-sm-2">{:__('返利设置')}:</label>
                        <div class="col-xs-12 col-sm-8">
                        </div>
                        <div class="col-xs-12 col-sm-8">
                            <div class="radio">
                                {foreach name="rebateTypeList" id="st"}
                                    <label for="c-rebate_type_{$key}">
                                        <input type="radio"  v-model="row.rebate_type" name="row[rebate_type]" id="c-rebate_type_{$key}" value="{$key}"  @click="rebateType = {$key}" > {$st}
                                    </label>
                                {/foreach}
                            </div>
                        </div>
                    </div>

                    <div class="form-group" v-if="rebateType == 2">
                        <label for="c-rebate_type" class="control-label col-xs-12 col-sm-2">{:__('返利设置')}:</label>
                        <div class="col-xs-12 col-sm-8">
                        </div>
                        <div class="col-xs-12 col-sm-8">
                            <table class="table table-bordered">
                                <tr class="alert-danger">
                                    <th>上级(元)</th>
                                    <th>上上级(元)</th>
                                    <th>上上上级(元)</th>
                                    <th>分销商(元)</th>
                                    <th>代理商(元)</th>
                                    <th>运营商(元)</th>
                                    <th>省代理(元)</th>
                                    <th>市代理(元)</th>
                                    <th>区代理(元)</th>
                                </tr>
                                <tr>
                                    <td><input type="text" class="form-control" name="rebate[pid]" value="{$rebates['pid']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[ppid]" value="{$rebates['ppid']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[pppid]" value="{$rebates['pppid']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[aid]" value="{$rebates['aid']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[aaid]" value="{$rebates['aaid']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[aaaid]" value="{$rebates['aaaid']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[province]" value="{$rebates['province']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[city]" value="{$rebates['city']?:0}"></td>
                                    <td><input type="text" class="form-control" name="rebate[area]" value="{$rebates['area']?:0}"></td>
                                </tr>
                            </table>
                        </div>
                    </div>

                    <div class="form-group" v-else>
                        <label for="c-commission" class="control-label col-xs-12 col-sm-2">{:__('Commission')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-commission" class="form-control" step="0.01" name="row[commission]" type="number" value="{$row['commission']?:''}">
                        </div>
                    </div>



                    <div class="form-group">
                        <label for="c-business_id" class="control-label col-xs-12 col-sm-2">{:__('Business_id')}:</label>
                        <div class="col-xs-12 col-sm-8">
                        </div>
                        <div class="col-xs-12 col-sm-8">
                            <select name="row[business_id]"  data-rule="required" v-model="row.business_id" class="form-control" id="c-business_id">
                                {foreach name="business" id="st"}
                                    <option value="{$st.id}">{$st.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="c-sale_number" class="control-label col-xs-12 col-sm-2">{:__('Sale_number')}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input id="c-sale_number" class="form-control" name="row[sale_number]" type="number" value="{$row['sale_number']?:'0'}">
                        </div>
                    </div>
                    
                </div>
                <div role="tabpanel" class="tab-pane" id="imgs">
                    <div class="form-group">
                        <label for="c-images" class="control-label col-xs-12 col-sm-2">商品相册:</label>
                        <div class="col-xs-12 col-sm-8">
                            <div class="input-group">
                                <input id="c-images" class="form-control hidden" size="50" name="row[images]" type="text" value="{$row.images?:''}">
                                <div class="input-group-addon no-border no-padding">
                                    <span><button type="button" id="plupload-images" class="btn btn-danger plupload" data-input-id="c-images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="true" data-preview-id="p-images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                                    <span><button type="button" id="fachoose-images" class="btn btn-primary fachoose" data-input-id="c-images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                                </div>
                                <span class="msg-box n-right" for="c-images"></span>
                            </div>
                            <ul class="row list-inline plupload-preview" id="p-images"></ul>
                        </div>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="spec">
                    <div class="form-group" v-for="(spec, index) in specs">
                        <label for="" class="control-label col-xs-12 col-sm-2">{{spec.name}}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <button class="btn  spec-btn" :class="item.selected?'btn-success':'btn-default'" type="button" @click="selectSpec(item)" v-for="item in spec.items">{{item.name}}</button>
                        </div>
                    </div>

                    <table class="table table-hover table-bordered" v-if="specInputItem && !row.chain_no">
                        <tr class="alert-success">
                            <th v-for="title in specInputItem.title">{{title}}</th>
                            <th>价格</th>
                            <th>库存</th>
                            <th>SKU/使用天数</th>
                            <th>操作</th>
                        </tr>
                        <tr v-for="(items,index) in specInputItem.items">
                            <th v-for="name in items.names">{{name}}</th>
                            <th>
                                <input type="text" class="form-control" :name="'spec['+items.key+'][price]'" :value="items.price">
                            </th>
                            <th>
                                <input type="text" class="form-control" :name="'spec['+items.key+'][store_count]'" :value="items.store_count">
                            </th>
                            <th>
                                <input type="text" class="form-control" :name="'spec['+items.key+'][sku]'" :value="items.sku">
                            </th>
                            <input type="hidden" :name="'spec['+items.key+'][spec_name]'" :value="items.spec_name">
                            <th>
                                <button class="btn btn-xs btn-danger btn-delone" type="button" @click="delInputItem(index, items.id)">
                                    <i class="fa fa-trash"></i>
                                </button>
                            </th>
                        </tr>
                    </table>
                    <table class="table table-hover table-bordered" v-else>
                        <tr class="alert-success">
                            <th>规格名称</th>
                            <th>价格</th>
                            <th>库存</th>
                        </tr>
                        {volist id="v" name="specs"}
                            <tr>
                                <th>{$v.spec_name}</th>
                                <th>
                                    <input type="text" class="form-control" name="spec[{$v.key}][price]" value="{$v.price}">
                                </th>
                                <th>
                                    <input type="text" class="form-control" readonly="readonly" name="spec[{$v.key}][store_count]" value="{$v.store_count}">
                                </th>
                                <input type="hidden" class="form-control" name="spec[{$v.key}][store_count]" value="{$v.store_count}">
                                <input type="hidden" class="form-control" name="spec[{$v.key}][sku]" value="{$v.sku}">
                                <input type="hidden" name="spec[{$v.key}][spec_name]" value="{$v.spec_name}">
                            </tr>
                        {/volist}
                    </table>
                </div>
                <div role="tabpanel" class="tab-pane" id="attribute">

                    <div class="form-group" v-for="(attr, index) in attributes">
                        <label for="" class="control-label col-xs-12 col-sm-2">{{attr.name}}:</label>
                        <div class="col-xs-12 col-sm-8">
                            <label class="radio-inline" v-if="attr.type == 1" :for="'row_attr_'+index+'_'+k" v-for="(v,k) in attr.values">
                                <input type="radio" :checked="v.checked?'checked':''"  :name="'row[attr]['+attr.id+']'" :value="v.value" @click="v.checked = !v.checked" :id="'row_attr_'+index+'_'+k">{{v.value}}
                            </label>
                           <input id="" v-if="attr.type == 3" class="form-control" :name="'row[attr]['+attr.id+']'"  type="text" :value="attr.values">

                           <label class="checkbox-inline" v-if="attr.type == 2" :for="'row_attr_'+index+'_'+k" v-for="(v,k) in attr.values">
                                <input type="checkbox" :checked="v.checked?'checked':''"  :name="'row[attr]['+attr.id+'][]'" :value="v.value" :id="'row_attr_'+index+'_'+k">{{v.value}}
                            </label>

                        </div>
                    </div>

                </div>
            </div>
        
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2"></label>
                <div class="col-xs-12 col-sm-8">
                    <button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button>
                    <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
<script src="/assets/js/vue/vue-resource.js"></script>
<script>

    var addVue = new Vue({
        el:'.add-form',
        data: {
            specs: [],
            attributes: [],
            category_id: {$row.category_id?:0},
            goods_type: {$row.goods_type?:1},
            selectedSpecs: [],
            specInputItem:[],
            row: {$row?:''},
            goodsId: {:input('ids')?:'0'},
            rebateType: {$row.rebate_type?:1},
        },
        mounted:function(){
            _this = this;
            var cid = _this.category_id;
            if(_this.goodsId > 0){
                this.getAttr(cid);
                this.getSpec(cid);
            }
        },
        methods: {
            getAttr: function(cid){
                _this = this;
                this.$http.post('{:url("goodsattribute/getCategoryAttr")}',{
                    cid: cid,
                    goods_id: _this.goodsId,
                },{
                    emulateJSON:true
                }).then(function(res){
                    if(res.data.code){
                        _this.attributes = res.data.data;
                    }
                },function(error){
                    layer.msg('查询分类属性出错');
                });
                
            },
            getSpec: function(cid){
                _this = this;
                this.$http.post('{:url("spec/getCategorySpec")}',{
                    cid: cid,
                    goods_id: _this.goodsId,
                },{
                    emulateJSON:true
                }).then(function(res){
                    if(res.data.code){
                        _this.specs = res.data.data;
                        _this.changeSelectSpec();
                    }
                },function(error){
                    layer.msg('查询分类规格出错');
                });
                
            },

            //选中
            selectSpec: function(item){
                console.log(item);
                if(typeof(item.selected) == 'undefine'){
                    this.set(item,'selected',true);
                } else {
                    item.selected = !item.selected;
                }


                this.changeSelectSpec();
            },
            //检查选中的选项值
            changeSelectSpec: function(){
                _this = this;
                var selectedSpecs = [];
                _this.specs.forEach(function(spec){
                    spec.items.forEach(function(item,index){
                        if(item.selected){
                            selectedSpecs.push(item.id);
                        }
                    })
                })
                this.selectedSpecs = selectedSpecs;
                console.log(this.selectedSpecs);
                this.getSpecInput();
            },
            //获取规格输入
            getSpecInput: function(){
                var ids = this.selectedSpecs.toString();
                _this = this;
                $.ajax({
                    url: '{:url("spec/getSpecInput")}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        ids: ids,
                        goods_id: _this.goodsId,
                    },
                    success:function(res){
                        if(res.code){
                            _this.specInputItem = res.data;
                        }
                    }
                })
                .fail(function() {
                    layer.msg('获取规格输入出错');
                });
            },
            //删除某行规格输入框
            delInputItem: function(index,id){
                //如果已经存在的，删除数据库的数据
                if(id){
                    _this = this;
                    this.$http.post('{:url("spec/delSpecPrice")}',{
                        id: id,
                    },{
                        emulateJSON:true
                    }).then(function(res){
                        if(res.data.code){
                            _this.specInputItem.items.splice(index,1);
                        } else{
                            layer.msg('删除规格价格出错');
                        }
                    },function(error){
                        layer.msg('删除规格价格出错');
                    });
                } else {
                    this.specInputItem.items.splice(index,1);
                }
            },
            //选择商品类型
            selectGoodsType: function(val) {
                console.log(val);
            }

        },
        watch: {
            category_id(newVal, oldVal){
                if(newVal){
                    this.getAttr(newVal);
                    this.getSpec(newVal);
                } else {
                    this.specs = [];
                    this.attributes = [];
                }
            }
        }
    });




</script>
